<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 200px;
            height: 200px;
            background: red;
            border: solid 5px plum;
            float: left;
            color: white;
            text-align: center;
            line-height: 200px;
            font-size: 50px;
        }
    </style>
</head>
<body>
    <div class="box">

    </div>
    <div class="box">

    </div>
    <div class="box">

    </div>
    <div class="box">

    </div>
    <div class="box">

    </div>
    <script>
        var box = document.getElementsByClassName("box");
        var futureTime = new Date('2021 1-1 00:00:00')
        // console.log(futureTime)

        var waitTime = setInterval(function(){
            var localTime = new Date();
            var timeDifference = futureTime - localTime;
            var millisecond = (timeDifference % 1000)
            var sec = ((timeDifference - millisecond) / 1000); //总秒数
            // console.log(sec)
            var second = (sec % 60)
            // console.log(second)
            var min =((sec-second)/60)  //总分数
            var minute = (min % 60)
            // console.log(minute)
            var hours = ((min - minute)/60)  //总小时数
            var hour = (hours % 60)
            // console.log(hour)
            var day1 = ((hours - hour)/24)  
            var dayy = (day1 % 24)
            var day = (day1-dayy) //总天数
            // console.log(day)
            box[0].innerHTML = day + '天';
            box[1].innerHTML = hour + '小时';
            box[2].innerHTML = minute + '分';
            box[3].innerHTML = second + '秒';

            var milliseconds = ''
            if (millisecond < 10){
                milliseconds = '00' + millisecond
            }else if (timeDifference<100 & timeDifference >=10){
                milliseconds = '0' + millisecond
            }else{
                milliseconds = millisecond
            }
            // console.log(milliseconds)
            box[4].innerHTML = milliseconds + '毫秒';
        },1)
    </script>
</body>
</html>